let app = getApp();
var siteinfo = require('../../siteinfo.js');
Page({
    data: {
        array: [{
            id: "",
            name: '请选择类型'
        },
        {
            id: 0,
            name: '考评员'
        },
        {
            id: 1,
            name: '考务员'
        },
        {
            id: 2,
            name: '考务技术员'
        },
        {
            id: 3,
            name: '督导员'
        },
        {
            id: 4,
            name: '讲师'
        }
        ],
        index: 0,
        floorstatus: false, // 返回顶部
        list: [], //放置返回数据的数组
        no_data: false, //“没有数据”的变量，默认false，隐藏
        reachLoading: true, //"上拉加载"的变量，默认false，隐藏
        current: 1, //第几页,第几次加载
        number: 10, //需要返回数据的个数
        name: '', //专家姓名
        type: '',//专家类型
        selectType:'9999'
    },

    onLoad: function (options) {

    },

    onShow: function () {
        this.getList()
    },
    //获取专家列表
    getList: function () {
        var _this = this
        _this.setData({
            current: 1,
            no_data: false
        });
        //console.log("_this.data.type",_this.data.type)
        app._get(siteinfo.selExperts, {
            number: _this.data.number,
            current: _this.data.current,
            name: _this.data.name,
            type: _this.data.type
        }, function (result) {
            _this.setData({
                list: result.data.records
            });
            if ((result.data.current * result.data.size) >= result.data.total) {
                _this.setData({
                    no_data: true
                });
            }
            wx.stopPullDownRefresh();
        })
    },
    //选择站点
    bindPickerChange: function (e) {
        var _this = this
        // console.log("_this.data.type", _this.data.type)
        _this.setData({
            index: e.detail.value,
            type: _this.data.array[e.detail.value].id
        })
        this.search()
    },
    handleSelectType: function (params) {
        this.setData({
            selectType:params.currentTarget.dataset.type,
            type: params.target.dataset.type
        })
        console.log(this.data.selectType);
        this.search()
    },
    //获取专家名称
    getName: function (e) {
        this.setData({
            name: e.detail.value
        })
    },
    //搜索
    search: function () {
        this.setData({
            no_data: false,
            current: 1,
            number: 10
        });
        this.getList()
    },
    onPullDownRefresh: function () {
        this.getList()
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        this.searchScrollLower();
    },

    //滚动到顶部触发事件
    searchScrollToupper: function () {
        let _this = this;
        wx.showLoading({
            title: '重新加载中...',
        })
        setTimeout(function () {
            _this.data.current = 1;
            _this.data.no_data = false;
            _this.onLoad();
            wx.hideLoading();
        }, 1000);
    },
    searchScrollLower: function () {
        let _this = this;
        if (_this.data.reachLoading && !_this.data.no_data) {
            _this.setData({
                current: _this.data.current + 1, //每次触发上拉事件，把current+1
            });
            wx.showLoading({
                title: '加载中',
            })
            //网络请求
            _this.reachAppendMsgList();
        }
    },
    /**
     * 上拉追加消息列表
     */
    reachAppendMsgList: function () {
        let _this = this;
        app._get(siteinfo.selExperts, {
            number: _this.data.number,
            current: _this.data.current,
            name: _this.data.name,
            type: _this.data.type
        }, function (result) {
            //以/n把字符串进行拆分
            var list = result.data.records;
            _this.setData({
                list: _this.data.list.concat(result.data.records)
            });
            if ((result.data.current * result.data.size) >= result.data.total) {
                _this.setData({
                    no_data: true
                });
            }
            wx.hideLoading();
        });
    },
    /**
     * 返回顶部
     */
    goTop: function (e) { // 一键回到顶部
        if (wx.pageScrollTo) {
            wx.pageScrollTo({
                scrollTop: 0
            })
        } else {
            wx.showModal({
                title: '提示',
                content: '当前微信版本过低，无法使用该功能，请升级到最新微信版本后重试。'
            })
        }
    },

    /**
     * 显示/隐藏 返回顶部按钮
     */
    onPageScroll: function (e) {
        this.setData({
            floorstatus: e.scrollTop > 200
        })
    },

    onShareAppMessage: function () {

    }
})